<?php

/**
 *      评级管理控制器
 */

namespace Home\Controller;
use Think\Controller;

class LoanController extends CommonController{

   public function _initialize() {
        parent::_initialize();
        $this->dbname = 'cash_user_grade';
    }
	
   function _filter(&$map) {

	   if(isset($_REQUEST['status']) && $_REQUEST['status'] != '')  $map['status'] =array('EQ', urldecode(I('status')));
     if(!isset($_REQUEST['orderField']) || $_REQUEST['orderField'] == '') $_REQUEST['orderField'] = 'sort';
	}

  
  public function _befor_add(){

	 $grade = M( $this->dbname )->field( 'grade' )->select();
	 $this->assign( 'grade',array_column( $grade,'grade') );
  }
  
  public function _befor_insert($data){

	  $check = M($this->dbname)->where("grade = '{$data['grade']}'")->getField('id');
	  if( !empty($check) ) $this->mtReturn(200,"该等级已添加！！".$data['grade'],$_REQUEST['navTabId'],true);

  	  $data['days']	   = implode( ',',$data['days'] );
  	  $data['creat_time'] = time();
  	  return $data;
  }
	

   
  public function _befor_update($data){
  	  $data['days']	   = implode( ',',$data['days'] );
 	  return $data;
  }
  
    public function _after_edit($id){
     
   }

   public function _befor_view($id){
	   
   }
   
   public function _befor_del($id){
	 
   }
   
   public function _after_del(){
     M($this->dbname)->where(array("kucun"=>array("elt",0)))->delete(); 	 
   }
}